﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeEdu.DTO
{
    using ServiceStack.OrmLite;
    using ServiceStack.DataAnnotations;
    using System.IO;

    public class File
    {
        /// <summary>
        /// 主键
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 课程ID
        /// </summary>
        public Guid CourseId { get; set; }

        /// <summary>
        /// 文件名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 大小(字节）
        /// </summary>
        public long Length { get; set; }

        /// <summary>
        /// 是否使用
        /// </summary>
        public bool Used { get; set; }

        /// <summary>
        /// 后缀名
        /// </summary>
        public string Extension { get; set; }

        /// <summary>
        /// 存储类型
        /// 0-服务器
        /// 1-阿里云
        /// </summary>
        public int StorageType { get; set; }

        /// <summary>
        /// 上传用户Id
        /// </summary>
        public Guid UpdateUserId { get; set; }

        /// <summary>
        /// 上传时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        [Ignore]
        public string DocType
        {
            get
            {
                string type = string.Empty;
                switch (this.Extension.ToLower())
                {
                    case ".jpg":
                    case ".png":
                    case ".gif":
                    case ".bmp":
                        type = "图片";
                        break;
                    case ".xls":
                    case ".doc":
                    case ".ppt":
                    case ".xlsx":
                    case ".pptx":
                        type = "文档";
                        break;
                    case ".mp4":
                        type = "视频";
                        break;
                    default:
                        type = "未知";
                        break;
                }
                return type;
            }
        }


        /// <summary>
        /// 文件路径
        /// </summary>
        [Ignore]
        public string FilePath { 
            get 
            {
                string path = Path.Combine(this.CourseId.ToString(), this.Name);
                return path;
            } 
        }

        [Ignore]
        public string Size
        {
            get
            {
                //Byte KB MB GB
                var kb=this.Length/1024;
                return string.Format("{0}KB", kb);
            }
        }
    }
}
